<template>
  <div class="app-container">
    <div class="action-container">
      <!--
      <el-button @click.prevent="handleImportClueEvent()" disabled>导出<i class="el-icon--right"></i></el-button>
       -->
    </div>
    <div class="filter-container">
      <el-date-picker v-model="listQuery.startDate" type="date" placeholder="起始时间" />
      <label>-</label>
      <el-date-picker v-model="listQuery.endDate" type="date" placeholder="终止时间" />
      <el-button class="filter-item" type="success" icon="el-icon-search" @click="resetFiler">重置</el-button>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>

    <el-table v-loading.body="listLoading" :data="list" element-loading-text="数据正在加载中，请稍后..." border fit highlight-current-row>
      <el-table-column align="center" label="ID" width="80">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="机关单位" width="240">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="线索数量">
        <template slot-scope="scope">
          {{ scope.row.totalCount }}
        </template>
      </el-table-column>
      <el-table-column label="处置数量">
        <template slot-scope="scope">
          {{ scope.row.disposalCount }}
        </template>
      </el-table-column>
      <el-table-column label="平均处置时长(天)">
        <template slot-scope="scope">
          {{ scope.row.disposalCount > 0 ? Math.ceil(scope.row.disposalDays / scope.row.disposalCount) : '-' }}
        </template>
      </el-table-column>
      <el-table-column label="办结数量">
        <template slot-scope="scope">
          {{ scope.row.closureCount }}
        </template>
      </el-table-column>
      <el-table-column label="平均办结时长(天)">
        <template slot-scope="scope">
          {{ scope.row.closureCount > 0 ? Math.ceil(scope.row.closureDays / scope.row.closureCount) : '-' }}
        </template>
      </el-table-column>
    </el-table>

    <div v-show="!listLoading" class="pagination-container">
      <el-pagination background :current-page.sync="listQuery.page" :page-sizes="[10,20,30,50]" :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script>
import { getCluePeriodStats } from '@/api/clue'

export default {
  components: {},
  filters: {
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: null,
      listQuery: {
        page: 1,
        size: 20,
        startDate: new Date().setDate(1),
        endDate: undefined
      }
    }
  },
  created() {
    // 查询数据
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getCluePeriodStats(this.listQuery).then(response => {
        this.listLoading = false
        this.list = response.data
        this.total = response.total
      }).catch(() => {
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.fetchData()
    },
    resetFiler() {
      this.listQuery.f_lk_period = undefined
      this.listQuery.page = 1
      this.listQuery.size = 20
      this.fetchData()
    },
    handleSizeChange(val) {
      this.listQuery.size = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.fetchData()
    }
  }
}
</script>
